
package com.avrio.json;

// <editor-fold defaultstate="collapsed" desc="import">
import java.io.IOException;
// </editor-fold>

@SuppressWarnings("serial")
class JsonString extends JsonValue {

    private final String string;

// <editor-fold defaultstate="collapsed" desc="JsonString()">

    public JsonString(String string) {

        if(string == null) {
            throw new NullPointerException("string is null");
        }
        this.string = string;
    }
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="write()">

    @Override
    protected void write(JsonWriter writer) throws IOException {
        writer.writeString(string);
    }
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="isString()">

    @Override
    public boolean isString() {
        return true;
    }
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="asString()">

    @Override
    public String asString() {
        return string;
    }
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="hashCode()">

    @Override
    public int hashCode() {
        return string.hashCode();
    }
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="equals()">

    @Override
    public boolean equals(Object object) {

        if(this == object) {
            return true;
        }
        if(object == null) {
            return false;
        }
        if(getClass() != object.getClass()) {
            return false;
        }

        JsonString other = (JsonString) object;
        return string.equals(other.string);
    }
// </editor-fold>
}
